<node>

A node is an objectarray which contains objectarrays and floarrays. In the same network (which is also a node), all nodes are the same size objectarray but the arrays they contain are usually different sizes, and those different sizes are defined in terms of the other array sizes in the same node. Index 0 in the node is used to quickly uniquely identify the node for the purpose of sorting and binary search for the node in any array its in. I've not decided what to put in index 0.

<question>
	Is it too slow to binarySearch nodes in arrays while also using the heapQueue?
	Example: Size 100,000 neural-network with 300 edges per node. Total 30,000,000 edges.
	To run all nodes 1 time on average (some run many times and some run none), time is:
	100,000 nodes * 300 edges * log(100,000).
	The log(100,000) is for looking up each edge-target node (neural child) in the network's heapQueue.
	The log(100,000) would be removed if edges were int index in heapQueue instead of node,
	but that prevents multiple heapQueues and the Big-O of adding/removing nodes in the network increases
	because int indexs in all nodes would have to be modified when the network's 1 array of node changes.
	The extra binary search for a node each time is probably better than an int index pointing at it.
	The binary search also makes finding errors easier.
</question>

<question>
	When adding or removing nodes from arrays, is it too slow for each node to have a unique value to sort it by in arrays? Usually the unique sort value can not be changed, so large parts of the array would have to be copied, unless it was not an array.
	Because nodes are executed much more often than the network shape changes, this is ok for nodes, but for the network's list of all nodes, this is a bigger problem. Maybe its not too big if unused nodes are kept in the network's array and are modified (but not moved in the network's array) and added to nodes when the network's shape should change. When nodes are deleted from the network, they become these "unused nodes".
	It is not too slow. This is a good design.
</question>

<question>
	What should the unique thing in index 0 of each node be? Double, double[0], Integer, int[0], String, byte[]?
	It should be fast to sort nodes in an array by their index 0.
	Example: Size 100,000 neural-network with 300 edges per node. Total 30,000,000 edges.
	100,000 size-1 arrays are not too much memory. The main cost is the speed of looking in index 0 of the array.
	<question>
		Should the unique thing at index 0 of each node ever be used to store data?
		A function that converts a network of nodes to a byte array could return a node with that byte array at index 0.
	</question>
	<question>
		Should the unique thing at index 0 of each node be a flo (Java type double) so evolved algorithms that use flo arrays can talk about nodes? Probably not, because those algorithms would probably not know about the shape of the networks. Its better to be consistent. All pointers to node should be type Object or all should be type flo, but not both.
	</question>
</question>

<question>
	Do the things in index 0 of each node need to be unique or just usually unique?
	For example, if they are a size 1 int array containing a random int that never changes, and 2 nodes have the same int, then a binary search for 1 of those 2 nodes would find the index of the first of those nodes. Do a linear search from there and find the second node with that int. Stop when the next node does not have that int. We were searching for a node, not an int, so we know which of these nodes it is. If too many nodes have the same int, throw an error. The only other option is to change that node's int in millions of nodes that use it, and that is not necessary should be avoided. When loading a saved network from bytes, randomize its nodes' ints, sort the nodes, and reorder the data in the nodes so the reordered nodes use the correct data. If that is done and there are too many duplicate ints, somebody must have tried to do that, and an error should be thrown.
	<problem>
		Only stable-sort can be used if 2 nodes in an array have the same int, to keep nodes and their data at indexs that are used together.
	</problem>
</question>

<question>
	Should the thing at index 0 of each node always be unique in the memory of a computer, and enforce that by keeping a Set of Integer (or some other data structure) of all nodes in memory?
	<question>
		Instead of that Set of Integer, should there be an array of node where each node is at the index of its int, and the array contains null if there is no node with that int? This would prevent garbage collection, but that is good because the int must be marked as unused when the node is garbage collected.
		We would still need a way to find which indexs are not used, and which indexs contain nonnull nodes that are not used.
	</question>
</question>

<question>
	In a heapQueue (which has 2 int arrays, 1 flo array, and 1 Object array) is it better for all 4 arrays to have the same size or for 1 of the int arrays to be 1 bigger than the other 3 arrays?
	It is faster for that int array to be 1 bigger because parent/child index calculations are faster,
	but it is simpler for all to be the same size.
	It causes more errors to be the same size because the 2 int arrays can be swapped and used that way, corrupting the data in them. But we can define a heapQueue as having the heap int array first and the reverse lookup int array second.
	If that int array is 1 bigger, it allows a memory optimization: Merge the size-1 int array at index 0 with a heapQueue int array that does not use index 0. Put the heapQueue int array at index 0 of the node.
	<question>
		Define all nodes this way?
		Define all nodes as having a heapQueue at indexs 0, 1, and 2. Index 0 is the heap int array pointing into indexs of this node. Index 1 is an int array pointing at the first int array. Index 2 is a flo array the heap is sorted by. The arrays at index 1 and 2 are aligned to eachother.
		Yes I think this is a good idea, but other heapQueue and/or other data structures (like one that allows fast complete sorting of a some nodes) should be allowed in other indexs of nodes.
	</question>
</question>

This will be the design of networks and nodes:

Network and node are the same type of thing. Node is an objectarray which contains objectarrays and floarrays and intarrays. In the same network (which is also a node), all nodes are the same size objectarray but the arrays they contain are usually different sizes, and those different sizes are defined in terms of the other array sizes in the same node.

Index 0 in the node is used to quickly uniquely identify the node for the purpose of sorting and binary search for the node in any array its in. Index 0 is always an int array whose first int is unique for the whole computer, not counting nodes on hard-drive or internet which must be modified before being copied to the memory of this computer.

For each computer, there is an Object array containing all the nodes in the memory of that computer. The nodes probably have different types (as defined above, different sizes and types of arrays). Some indexs in the main Object array are null and some may have nodes which are not used and are waiting to be used. If those exist, something would have to remember which indexs they are.

When a network is loaded from bytes, all index-0 ints in the nodes are changed but not reordered. They are changed to some set of ints which this computer is not using, and they are put in the main Object array at those int indexs. Because the ints are not reordered relative to eachother, the data of the nodes is not modified. That data would be modified later if changes are made to the network shape, but that is a different action than loading the network from bytes.

All nodes have a heapQueue (which may be empty) at indexs 0, 1, and 2. Index 0 is the heap int array pointing into indexs of this node. Index 1 is an int array pointing at the first int array. Index 2 is a flo array the heap is sorted by. The arrays at index 1 and 2 are aligned to eachother.

I have considered speed and memory size in this design and think it is the best balance of those which allows networks/nodes to be completely represented as Object, double, and int arrays.

<question>
	Because node and network are the same type of thing, should each node have a function (a Java Object) that executes the node?
	Should that function use the node's heapQueue, or should that be done by a hard-coded function?
	Parallel to this computer's main array of node, there should be a function array, 1 function for each node.
	<question>
		Should the function of each node be used for recursion through multiple heapQueues?
		When I choose to execute a node, when should I instead (or also?) execute the node at the top of its heapQueue?
		One option (but should not be the only option) is to know the current flo value the current node has (in the current heapQueue), and see if the highest flo in this node's heapQueue is higher than that, and recurse if so, probably decreasing that flo. Should the parent heapQueue's flo also decrease to that same flo?
		<question>
			Should this be allowed?: Always recurse exactly 5 times, and if that can not be done (because of duplicate node or leaf node) then use flo value 0 to fill in the flo array thats at least size 5? The old design of audivolv where a network had the only heapQueue is compatible with this if always recurse exactly 1 deep.
			I want variable size recursion.
		</question>
		<question>
			Should recursion be reentrant, meaning its path can include the same node (dupNode) multiple times? How would that affect dupNode's heapQueue?
		</question>
		<question>
			Use a node's heapQueue as the execution stack for a network? That would prevent reentrant recursion and is slow.
			To implement that, when a node is about to execute, increase its flo value in the stack's heapQueue so it is at the top.
			That is very similar to the original design of audivolv where the network had the only heapQueue, but this way any node can have a heapQueue. Should the stack be a different node than the network's main node?
		</question>
		<question>
			When recursing nodes and their heapQueues, should anything depend on if the highest node in the current heapQueue is in the parent node's heapQueue?
		</question>
	</question>
</question>

Example: b is a size-5 neural-network with nodes c, d, e, and f:
b's heapQueue: c=5 d=4 e=3 f=2.5
c's heapQueue: e=10 d=5
d's heapQueue: f=-3
e's heapQueue: empty
f's heapQueue: c=3

There should be many ways to do recursion. Give an example of recursing this network:

Maybe the flo in this stack should decrease by 1 in each recursion, and allow the child to choose how to distribute whats left.
These are views of the stack after each change to the stack:
stack: b=16 c=0 d=0 e=0 f=0
stack: c=8 b=7 d=0 e=0 f=0
stack: b=7 e=4 c=3 d=0 f=0
Thats not useful. The ways of recursion should be evolvable.

<question>
	Should the stack of flos (which can, right now, be read and written) be viewed as a variable size flo array in the top node on the stack?
	For example, recurse 7 nodes deep, not doing anything, and on the last node, iterate over quantity of childs * 7 * size of some other array in that node. Each time, execute a Flofunc on a flo array size 3 (or more if it does other things).
	If recursion depth is constant (fill in with 0.0 if necessary) then the whole stack of flos can be used instead of 1 at a time.
	If its constant 7, size would be 7+2 or more.
	This is probably a good design, but only if it can be done efficiently.
	<question>
		How can it efficiently detect a duplicate node in the stack?
	</question>
	<question>
		In the middle of a recursion, should the current node be able to use the current flo stack, and the same for all steps in the recursion?
		That would square the Big-O of 1 network execution, but if its limited to log size, log squared is sometimes ok.
	</question>
	<question>
		How to limit variable size recursive depth? Should an option be to limit it a constant defined in the network algorithm?
	</question>
	<question>
		Should Flofunc execution on a flo array containing multiple flos from heapQueue be required to conserve total value of those flos from the heapQueue? For example, decrease flo in parent heapQueue by 5.5 and increase flo in this heapQueue by 2 and parent of parent's heapQueue's flo increases by 3.5. Execution should cost something, so maybe it should increase by 2.5 instead of 3.5, or some other combination totaling 1 less than it was.
		There are many ways a flo array can be used to trade (but not create or destroy) flos in multiple heapQueues.
		For example, do not include the first heapQueue, and the array includes 0 for each heapQueue except the first. Whatever it changes the 0s to, subtract that (and subtract 1 for the cost of executing) from the first heapQueue (for the first part of this path currently executing).
		That way, stupid evolved algorithms will decrease the flos for all nodes in the root heapQueue quickly and the network will return quickly. Root heapQueue flos will get small and other heapQueue flos will get big but not be used.
		Or, root heapQueue flos will get big but recursion will end at depth 1 because other heapQueue flos will be small.
		Total execution time can be approximately limited to time proportional to X by adding X to flos in the root heapQueue.
		That conservation-of-heapQueue-flos should be an option (choosable by evolution), not the only way to control recursion.
	</question>
</question>

<question>
	How to efficiently detect flos that evolved Flofuncs in evolved networks have made too high, or Double.NaN, Double.POSITIVE_INFINITY, or Double.NEGATIVE_INFINITY?
	Maybe it should be searched for rarely, and if the evolved thing ever does it, never use that evolved thing again.
	When a network/Flofunc combination is created, its first few thousand executions should have the Flofunc wrapped in a flo verifying Flofunc that throws if any flo is out of range.
	Sometimes, do that wrapping again to verify it still works.
	That will work fast and accurate enough. Do it.
</question>

<question>
	Of all the possible ways to do control-flow, are any prevented if I stop designing complex things now and do one of the simpler designs, given that every node has indexs 0 1 and 2 as a heapQueue and other designs described above?
	Probably it will not restrict future designs, so lets do that now.
</question>

<question>
	One last thing before I start writing code again:
	Using dyanmicly generated Java, how to create functions that iterate over certain combinations of arrays?
	How to run a sequence of those?
	How to loop over 1 of those? For example, if you have 2 arrays x and y, function g iterates over y,
	and the question is how to run g in a loop size x?
</question>

</node>